﻿using Dapper;
using Domain.Entity.zct;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repository
{
    public class UserRoleRepository : IUserRoleRepository
    {
        //连接字符串
        string con = "Data Source=121.37.93.71;Initial Catalog=CSSL_ZCTWMS;User ID=sa;Password=geili@2025;Encrypt=False";

        public async Task<List<UserRole>> GetAll()
        {
            using (SqlConnection sqlConnection = new SqlConnection(con))
            {
                await sqlConnection.OpenAsync();
                string sql = $@"select user_role_id,user_id,role_id from [dbo].[zct_user_role]";
                return sqlConnection.Query<UserRole>(sql).ToList();
            }
        }

        public async Task<List<UserRole>> Getuid(int uid)
        {
            using (SqlConnection sqlConnection = new SqlConnection(con))
            {
                await sqlConnection.OpenAsync();
                string sql = $@"select user_role_id,user_id,role_id from [dbo].[zct_user_role] where user_id={uid}";
                return sqlConnection.Query<UserRole>(sql).ToList();
            }
        }
    }
}
